package com.jakesepicstuff.jnotepad;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class FontAndColor extends JFrame{
	
	Dimension frameSize = new Dimension(250, 200);
	
	JLabel italicLabel, boldLabel;
	
	JCheckBox italicCheckBox, boldCheckBox;
	
	JComboBox fontChoice;
	
	JButton changeColor, changeBgColor;
	
	Color colorChooser;
	
	String fontOptions[] = {"Fonts comings soon..."};
	
	//String fontOptions[] = {"Change Font","Default", "Verdana", "Arial", "Tahoma", "Helvetica", "Jester"};
	
	boolean italicIsChecked = false;
	boolean boldIsChecked = false;
	
	// CONSTRUCTOR
	public FontAndColor() {
		
		setTitle("Change Font & Color");
		setSize(frameSize);
		setLocationRelativeTo(null);
		setLayout(new FlowLayout());
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setVisible(true);
		
		initComponents();
	}
	
	// INITIALIZE COMPONENTS
	private void initComponents() {
		
		italicLabel = new JLabel("Italic");
		
		boldLabel = new JLabel("Bold");
		
		italicCheckBox = new JCheckBox();
		
		boldCheckBox = new JCheckBox();
		
		fontChoice = new JComboBox(fontOptions);
		fontChoice.setSelectedIndex(0);
		fontChoice.setPreferredSize(new Dimension(200, 30));
		
		changeColor = new JButton("Change Text Color");
		changeColor.setPreferredSize(fontChoice.getPreferredSize());
		
		changeBgColor = new JButton("Change BG Color");
		changeBgColor.setPreferredSize(fontChoice.getPreferredSize());
		
		addComponents();
	}
	
	// ADD COMPONENTS
	private void addComponents() {
		
		add(italicLabel);
		add(italicCheckBox);
		
		add(boldLabel);
		add(boldCheckBox);
		
		add(fontChoice);
		
		add(changeColor);
		
		add(changeBgColor);
		
		changeColor.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				
				colorChooser = JColorChooser.showDialog(null, "Change Color", Color.BLACK);
				
				if (colorChooser == null) {
					
					JOptionPane.showMessageDialog(null, "Color has defaulted to black");
					Display.textArea.setForeground(Color.BLACK);
				} else {
				
					Display.textArea.setForeground(colorChooser.getColor("Test", colorChooser));
				}
					 
			}
		});
		
		changeBgColor.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				
				colorChooser = JColorChooser.showDialog(null, "Change BG Color", Color.WHITE);
				
				if (colorChooser == null) {
					
					JOptionPane.showMessageDialog(null, "Color has defaulted to white");
					Display.textArea.setBackground(Color.WHITE);
				} else {
				
					Display.textArea.setBackground(colorChooser.getColor("Test", colorChooser));
				}
			}
		});
		
		italicCheckBox.addItemListener(new ItemListener() {
			
			@Override
			public void itemStateChanged(ItemEvent arg0) {
				
				italicIsChecked = !italicIsChecked;
				
				if (italicIsChecked) {
					
					Display.textArea.setFont(new Font("Dialog", Font.ITALIC, 12));
				} else {
					
					Display.textArea.setFont(new Font("Dialog", Font.PLAIN, 12));
				}
				
				System.out.println("Italic is " + italicIsChecked);
			}
		});
		
		boldCheckBox.addItemListener(new ItemListener() {
			
			@Override
			public void itemStateChanged(ItemEvent arg0) {
				
				boldIsChecked = !boldIsChecked;
				
				if (boldIsChecked) {
					
					Display.textArea.setFont(new Font("Dialog", Font.BOLD, 12));
				}
				
				System.out.println("Bold is " + boldIsChecked);
			}
		});
		
		fontChoice.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				
				JComboBox cb = (JComboBox) arg0.getSource();
				
				Object selectedItem = cb.getSelectedItem();
				
				if (selectedItem == "Arial") {
					
					Display.textArea.setFont(new Font("Arial", Font.PLAIN, 12));
					System.out.println("User chose arial");
				} else if (selectedItem == "Verdana") {
					
					Display.textArea.setFont(new Font("Verdana", Font.PLAIN, 12));
					System.out.println("User chose Verdana");
				} else if (selectedItem == "Verdana") {
					
					Display.textArea.setFont(new Font("Tahoma", Font.PLAIN, 12));
					System.out.println("User chose Tahoma");
				} else if (selectedItem == "Helvetica") {
					
					Display.textArea.setFont(new Font("Helvetica", Font.PLAIN, 12));
					System.out.println("User chose Helvetica");
				} else if (selectedItem == "Jester") {
					
					Display.textArea.setFont(new Font("Jester", Font.PLAIN, 12));
					System.out.println("User chose Jester");
				} else {
					
					System.out.println("Dafuq?!");
				}
			}
		});
	}
}